package com.appcan.base;

import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ConCurrentClient {

    private static Logger log = Logger.getLogger(ConCurrentClient.class);
    private ArrayList<TaskCall> list = new ArrayList<TaskCall>();

    public void addAction(TaskCall callable) {
        list.add(callable);
    }

    public void execute() throws Exception {
      if(list.size()==1){
         list.get(0).call();
      }else {
          ExecutorService service = Executors.newCachedThreadPool();
          service.invokeAll(list);
          service.shutdown();
         
      }
    }
}